﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using HouseBotScreensaver.Properties;

namespace HouseBotScreensaver
{
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {
            InitializeComponent();
        }

        private void SettingsForm_Load(object sender, EventArgs e)
        {

            foreach (Color colour in new ColorConverter().GetStandardValues())
            {
                if (!colour.IsSystemColor)
                {
                    drpBackgroundColour.Items.Add(colour.ToKnownColor());
                    drpFontColour1.Items.Add(colour.ToKnownColor());
                    drpFontColour2.Items.Add(colour.ToKnownColor());
                    drpFontColour3.Items.Add(colour.ToKnownColor());
                    drpFontColour4.Items.Add(colour.ToKnownColor());
                }
            }

            numPort.Value = Settings.Default.HouseBotPort;
            txtAddress.Text = Settings.Default.HouseBotHost;
            txtPassword.Text = Settings.Default.HouseBotPassword;

            numInterval.Value = Settings.Default.Interval / 1000;
            numSpace.Value = Settings.Default.SpaceBetweenLabels;
            drpBackgroundColour.SelectedText = Settings.Default.BackgroundColour;
            numBackgroundOpacity.Value = int.Parse(Settings.Default.BackgroundOpacity.ToString());

            txtLabel1.Text = Settings.Default.Label1Text;
            txtLabel2.Text = Settings.Default.Label2Text;
            txtLabel3.Text = Settings.Default.Label3Text;
            txtLabel4.Text = Settings.Default.Label4Text;

            numFontSize1.Value = decimal.Parse(Settings.Default.Label1FontSize.ToString());
            numFontSize2.Value = decimal.Parse(Settings.Default.Label2FontSize.ToString());
            numFontSize3.Value = decimal.Parse(Settings.Default.Label3FontSize.ToString());
            numFontSize4.Value = decimal.Parse(Settings.Default.Label4FontSize.ToString());

            drpFontColour1.SelectedText = Settings.Default.Label1FontColour;
            drpFontColour2.SelectedText = Settings.Default.Label2FontColour;
            drpFontColour3.SelectedText = Settings.Default.Label3FontColour;
            drpFontColour4.SelectedText = Settings.Default.Label4FontColour;

            chkFade.Checked = Settings.Default.Fade;
            chkDim.Checked = Settings.Default.DimLabels;
            numDim.Value = Settings.Default.DimLevel;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Settings.Default.HouseBotPort = int.Parse(numPort.Value.ToString());
            Settings.Default.HouseBotHost = txtAddress.Text;
            Settings.Default.HouseBotPassword = txtPassword.Text;

            Settings.Default.Interval =  int.Parse(numInterval.Value.ToString()) * 1000;
            Settings.Default.SpaceBetweenLabels =int.Parse(numSpace.Value.ToString());
            Settings.Default.BackgroundColour = drpBackgroundColour.Text;
            Settings.Default.BackgroundOpacity = int.Parse(numBackgroundOpacity.Value.ToString());

            Settings.Default.Label1Text = txtLabel1.Text;
            Settings.Default.Label1FontSize = int.Parse(numFontSize1.Value.ToString());
            Settings.Default.Label1FontColour = drpFontColour1.Text;

            Settings.Default.Label2Text = txtLabel2.Text;
            Settings.Default.Label2FontSize = int.Parse(numFontSize2.Text.ToString());
            Settings.Default.Label2FontColour = drpFontColour2.Text;

            Settings.Default.Label3Text = txtLabel3.Text;
            Settings.Default.Label3FontSize = int.Parse(numFontSize3.Text.ToString());
            Settings.Default.Label3FontColour = drpFontColour3.Text;

            Settings.Default.Label4Text = txtLabel4.Text;
            Settings.Default.Label4FontSize = int.Parse(numFontSize4.Text.ToString());
            Settings.Default.Label4FontColour = drpFontColour4.Text;

            Settings.Default.Fade = chkFade.Checked;
            Settings.Default.DimLabels = chkDim.Checked;
            Settings.Default.DimLevel = int.Parse(numDim.Text.ToString());

            Settings.Default.Save();

            Application.Exit();
        }
    }
}
